package com.beetlestech.nfe.main.biz.com.impl;
import java.util.List;
import com.beetlestech.nfe.fw.core.biz.AbstractDBLogic;
import com.beetlestech.nfe.fw.core.util.CollectionUtil;
import com.beetlestech.nfe.main.biz.com.HbVTeacherLogin;
import com.beetlestech.nfe.main.biz.com.dto.UserInfoDTO;
import com.beetlestech.nfe.main.biz.constant.CommonConstant;
import com.beetlestech.nfe.main.biz.constant.CtgCodeConstant;
import com.beetlestech.nfe.main.biz.constant.HbMessageCode;
import com.beetlestech.nfe.main.db.constant.SQLConstant;
import com.beetlestech.nfe.main.db.view.VteacherlogininfoDTO;
public class HbVTeacherLoginImpl extends AbstractDBLogic implements HbVTeacherLogin, CtgCodeConstant, HbMessageCode, CommonConstant, SQLConstant {

	protected static final String SH_INFO = "職員情報データ";
	
	@Override
	public UserInfoDTO getLoginTeacherInfo(
			String loginName, String password) {
		VteacherlogininfoDTO vteacherlogininfoDTO =new VteacherlogininfoDTO();
		vteacherlogininfoDTO.setusername(loginName);
		List<VteacherlogininfoDTO> teacherDTOs=queryDAO.queryForObjectList(VteacherlogininfoDTO.EQUAL_SEARCH, vteacherlogininfoDTO);
		UserInfoDTO teacherLoginInfo = null;
		if (CollectionUtil.isEmpty(teacherDTOs)) {
			//検出件数が0件の場合
			createApplicationException(M00010WC, SH_INFO);
		} else {
			//処理１で2件以上取得できた場合は、「ApplicationException」を返す
			if(teacherDTOs.size()>1){
               createApplicationException(M10190WS, SH_INFO);
			}
			else{
				teacherLoginInfo=convertToVTeacher(teacherDTOs.get(0));
				if(null != password && "" != password && ! password.equals(teacherLoginInfo.getpassword())){
					createApplicationException(M00010WC, SH_INFO);
				}
			}
		} 
		
		return teacherLoginInfo;
	}
	private UserInfoDTO convertToVTeacher(VteacherlogininfoDTO item){
		UserInfoDTO teacherloginDTO = new UserInfoDTO();
		teacherloginDTO.setIsCourseManage(null);
		teacherloginDTO.setIsExamQuestionManage(null);
		teacherloginDTO.setIsHomeWorkManage(null);
		teacherloginDTO.setIsStudentManage(null);
		teacherloginDTO.setIsSystemManage(null);
		teacherloginDTO.setIsTeacherManage(null);
		teacherloginDTO.setusrid(item.getusrid());
		teacherloginDTO.setusername(item.getusername());
		teacherloginDTO.setpassword(item.getpassword());
		teacherloginDTO.setTeacherid(item.getusrid());
		return teacherloginDTO;
	}
}
